<?php

namespace App\Http\Model;

use App\Http\Services\BoardExtendServices;
use App\Http\Services\MaximumGoldRoomServices;
use App\Http\Services\MsgServices;
use App\Lib\Snowflake\SnowflakeGenerator;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;


class FinanceWealth extends Base
{
    protected $tablePrefix = '';
    protected $table = 'finance_wealth_rank';
    protected $streamTable = 'finance_wealth_stream';
    protected $roomStreamTable = 'finance_room_wealth_stream';


    private $redis_charts_user_wealth_day = "FINANCE:CHARTS:USER:WEALTH:DAY:"; // FINANCE:CHARTS:USER:WEALTH:DAY:2018-11-22
    private $redis_charts_user_wealth_week = "FINANCE:CHARTS:USER:WEALTH:WEEK:"; // FINANCE:CHARTS:USER:WEALTH:DAY:2018-11-222018-11-20
    private $redis_charts_user_wealth_month = "FINANCE:CHARTS:USER:WEALTH:MONTH:"; // FINANCE:CHARTS:USER:WEALTH:DAY:2018-11
    private $redis_charts_user_wealth_all = "FINANCE:CHARTS:USER:WEALTH:ALL";

    private $redis_finance_user_wealth_before_total = 'FINANCE:CHARTS:USER:WEALTH:BEFORE:TOTAL';
    private $redis_finance_user_wealth_total = 'FINANCE:CHARTS:USER:WEALTH:TOTAL';
    // 最多金房-个人-富豪榜
    private $redis_charts_user_wealth_day_maximum_gold = "FINANCE:CHARTS:USER:WEALTH:DAY:MAXIMUM:GOLD:"; // FINANCE:CHARTS:USER:WEALTH:DAY:MAXIMUM:GOLD:2018-11-22
    private $redis_charts_user_wealth_week_maximum_gold = "FINANCE:CHARTS:USER:WEALTH:WEEK:MAXIMUM:GOLD:"; // FINANCE:CHARTS:USER:WEALTH:DAY:MAXIMUM:GOLD:2018-11-222018-11-20
    private $redis_charts_user_wealth_month_maximum_gold = "FINANCE:CHARTS:USER:WEALTH:MONTH:MAXIMUM:GOLD:"; // FINANCE:CHARTS:USER:WEALTH:DAY:MAXIMUM:GOLD:2018-11
    private $redis_charts_user_wealth_all_maximum_gold = "FINANCE:CHARTS:USER:WEALTH:ALL:MAXIMUM:GOLD";

    public $timestamps = false;

    private $redis_cache_finance_user_wallet = "CACHE:FINANCE:USER:WALLET";



    private $redis_finance_user_wealth_rank = "FINANCE:USER:WEALTH:RANK";
    private $fullScreenMisson = 'SHOW:FULLSCREEN:USER:';//飘屏权限缓存 string
    
    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
        $this->tablePrefix = env('DB_PREFIX');
    }
    
    //财富值明细
    public function getWealthRankData()
    {
        $this->tablePrefix = env('DB_PREFIX');
        $condition = [];
        $fields = ['rank_id', 'rank_pid', 'rank_name', 'image', 'min_value', 'max_value', 'small_image', 'join_animation', 'level','s_small_image','join_animation_svg','join_animation_big','join_animation_color'];
        $document = DB::table($this->table)
            ->where($condition)
            ->orderBy('min_value', 'asc')
            ->get($fields);
        
        $result = self::objToArray($document);
        foreach($result as $key=>$val) {
            $val['image'] = empty($val['image']) ? "" : getPicDomain() . $val['image'];
            $val['small_image'] = empty($val['small_image']) ? "" : getPicDomain() . $val['small_image'];
            $val['s_small_image'] = empty($val['s_small_image']) ? "" : getPicDomain() . $val['s_small_image'];
            $val['join_animation'] = empty($val['join_animation']) ? "" : getPicDomain() . $val['join_animation'];
            $val['join_animation_svg'] = empty($val['join_animation_svg']) ? "" : getPicDomain() . $val['join_animation_svg'];
            $val['join_animation_big'] = empty($val['join_animation_big']) ? "" : getPicDomain() . $val['join_animation_big'];
            $sub_rank = $val;
            unset($sub_rank['rank_id'],$sub_rank['rank_pid']);
            $val['sub_rank'][] = $sub_rank;
            $result[$key] = $val;
        }

        return $result;
    }



    
    //获取距离最近的财富等级
    public function getNearWealthRank($wealth_balance)
    {
        $table_finance_wealth_rank = $this->tablePrefix . 'finance_wealth_rank';
        $document = DB::select("select rank_id,rank_pid,rank_name,image,small_image,join_animation from $table_finance_wealth_rank where rank_pid = 0 and $wealth_balance >= min_value and IF(max_value = 0,1,$wealth_balance <= max_value) limit 1");
        $result = self::objToArray($document);
        for ($i = 0; $i < count($result); $i++){
            $result[$i]['image'] = $result[$i]['image'] ? getPicDomain() . $result[$i]['image'] : "";
            $result[$i]['small_image'] = $result[$i]['small_image'] ? getPicDomain() . $result[$i]['small_image'] : "";
            if (!empty($result[$i]['join_animation'])){
                $result[$i]['join_animation'] = $result[$i]['join_animation'] ? getPicDomain() . $result[$i]['join_animation'] : "";
            }
        }
        if(isset($result[0]) && !empty($result)){
            return $result[0];
        }
        return $result;
    }



    /**
     * 更新财富值
     * @param $user_id
     * @param $from_user_id
     * @param $room_id
     * @param $wealth_type  0.礼物、1.守护、2.商品、3、4.购买礼包、13.开箱子 20.任务奖励 21.转盘奖券购买 99.比心计时礼物
     * @param $wealth_value
     * @param $TimedGoodsScore 比心礼物分数
     * @return boolean
     */
    public function inc($user_id, $from_user_id, $room_id, $wealth_type, $wealth_value, $room_wealth_value = 0, $TimedGoodsScore=0, $gift_stream_id=0){
        DB::table("finance_wallet")
            ->where(['user_id'=>$user_id])
            ->increment('wealth_balance',$wealth_value,['change_timestamp'=> time()]);

        $wallet = DB::table('finance_wallet')
            ->where('user_id', '=', $user_id)
            ->first(['wealth_balance']);

        //增加一个track_id; add by zxiaofee
        // $trackId = SnowflakeGenerator::generateId('finance_wealth_stream');
        DB::table("finance_wealth_stream")->insert([
            // "track_id" => $trackId,
            "gift_stream_id" => $gift_stream_id,
            "user_id" => $user_id,
            "room_id" => $room_id,
            "wealth_value" => $wealth_value,
            "from_user_id" => $from_user_id,
            "wealth_type" => $wealth_type,
            "wealth_balance" => $wallet->wealth_balance,
            "room_wealth_value" => $room_wealth_value,
            "change_timestamp" => time()
        ]);

        Redis::DEL($this->redis_cache_finance_user_wallet . ':' . $user_id); //清除缓存
        $this->sendRongMsg($user_id);
        $this->inc_charts($user_id, $wealth_value, $room_id, $TimedGoodsScore);
        return true;
    }

    //财富值更新通知
    public function sendRongMsg($user_id){
        //用户财富值大于系统配置总财富值时候发送融云消息推送(飘屏限制通知)
        $userWealthInfo = DB::table("finance_wallet")->where(['user_id'=>$user_id])->first();
        $userWealthInfo = $this->objToArray($userWealthInfo);

        $systemModel = new System();
        $configMap = $systemModel->get_config();
        $sys_show_full_screen = empty($configMap['full_screen_cofing']['value']) ? 0 : $configMap['full_screen_cofing']['value'];
        $sys_show_full_screen = json_decode($sys_show_full_screen,true);

        if(!empty($sys_show_full_screen) && empty(Redis::get($this->fullScreenMisson.$user_id))){
            $data = [];
            foreach($sys_show_full_screen as $k=>$val){
                if($userWealthInfo['wealth_balance'] >= $val){
                    $data[$k] = 1;
                }else{
                    $data[$k] = 0;
                }
            }

            //发送融云可以查看飘屏通知
            $msgService = new MsgServices();
            $msgService->can_see_full_screen_msg($user_id,$data);
            Redis::set($this->fullScreenMisson.$user_id,1);
        }
    }

    /**
     * 增加房间下的财富榜
     *
     * @param $user_id
     * @param $wealth_value
     * @param $room_id
     * @param $wealth_type
     */
    public function inc_charts($user_id, $wealth_value, $room_id, $TimedGoodsScore=0){
        // 比心值 加入排行榜
        $wealth_value += $TimedGoodsScore;// 比心礼物值追加到
        if ($wealth_value<=0){
            return true;
        }
        $str_month = date("Ym");
        $str_day = date("Ymd");
        $startWeekDate = Carbon::today()->startOfWeek();
        $endWeekDate = Carbon::today()->endOfWeek();

        $str_week_start=date('Ymd',strtotime($startWeekDate));
        $str_week_end=date('Ymd',strtotime($endWeekDate));
        //本日
        $user_day_key = $this->redis_charts_user_wealth_day . $str_day;
        //本周
        $user_week_key = $this->redis_charts_user_wealth_week . $str_week_start . $str_week_end;
        $user_all_key = $this->redis_charts_user_wealth_all;
        //本月
        $user_month_key = $this->redis_charts_user_wealth_month . $str_month;


        Redis::zincrby($user_day_key, $wealth_value, $user_id);
        Redis::zincrby($user_week_key, $wealth_value, $user_id);
        Redis::zincrby($user_all_key, $wealth_value, $user_id);
        Redis::zincrby($user_month_key, $wealth_value, $user_id);
        // $this->inc_user_total_score($user_id);
        if(Redis::TTL($user_day_key) == -1){
            Redis::EXPIRE($user_day_key, 2 * 24 * 3600);
        }
        if(Redis::TTL($user_week_key) == -1){
            Redis::EXPIRE($user_week_key, 2 * 7 * 24 * 3600);
        }
        if(Redis::TTL($user_month_key) == -1){
            Redis::EXPIRE($user_month_key, 2 * 31 * 24 * 3600);
        }
    }

    /**
     * 获取用户财富值排行榜
     * @param $type 1.天 2.周 -.月 3.总
     * @param $index
     * @param $count
     * @return array
     */
    public function get_user_charts($type, $index, $count){
        $str_month = date("Ym");
        $str_day = date("Ymd");
        $first=1;
        $w=date('w',strtotime($str_day));
        $str_week_start=date('Ymd',strtotime("$str_day -".($w ? $w - $first : 6).' days'));
        $str_week_end=date('Ymd',strtotime("$str_week_start +6 days"));
        $user_day_key = $this->redis_charts_user_wealth_day . $str_day;
        $user_week_key = $this->redis_charts_user_wealth_week . $str_week_start . $str_week_end;
        $user_month_key = $this->redis_charts_user_wealth_month . $str_month;
        $user_all_key = $this->redis_charts_user_wealth_all;

        $key = $user_day_key;

        if ($type == 1){
            $key = $user_day_key;
        }
        if ($type == 2){
            $key = $user_week_key;
        }
        if ($type == 3){
            $key = $user_month_key;
        }
        return Redis::zrevrange($key, $index, $index+$count-1, 'withscores');
    }

    /**
     * 富豪榜-最多金
     * @param $type 1.天 2.周 -.月 3.总
     * @param $index
     * @param $count
     * @return array
     */
    public function get_user_charts_maximum_gold($type, $index, $count)
    {
        $str_month = date("Ym");
        $str_day = date("Ymd");
        $first=1;
        $w=date('w',strtotime($str_day));
        $str_week_start=date('Ymd',strtotime("$str_day -".($w ? $w - $first : 6).' days'));
        $str_week_end=date('Ymd',strtotime("$str_week_start +6 days"));
        $user_day_key = $this->redis_charts_user_wealth_day_maximum_gold . $str_day;
        $user_week_key = $this->redis_charts_user_wealth_week_maximum_gold . $str_week_start . $str_week_end;
        $user_month_key = $this->redis_charts_user_wealth_month_maximum_gold . $str_month;
        $key = $user_day_key;
        if ($type == 1){
            $key = $user_day_key;
        }

        if ($type == 2){
            $key = $user_week_key;
        }

        if ($type == 3){
            $key = $user_month_key;
        }

        return Redis::zrevrange($key, $index, $index + $count - 1, 'withscores');
    }

    public function set_user_rank($user_id, $rank_id){
        Redis::HSET($this->redis_finance_user_wealth_rank, $user_id, $rank_id);
    }

    public function get_user_rank($user_id){
        return Redis::HGET($this->redis_finance_user_wealth_rank, $user_id);
    }
    
    /**
     * 清除用户钱包缓存
     * @param int $wallet_id
     */
    public function clear_cache(int $wallet_id = 0){
        Redis::DEL($this->redis_cache_finance_user_wallet . ':' . $wallet_id); //清除缓存
    }
    
    /**
     * 获取流水详情
     * @param int $room_id
     * @param int $date
     * @param int $page
     * @param int $length
     * @return array
     */
    public function get_finance_wealth_stream(int $room_id, int $date, int $page, int $length){
        $date = date('Y-m-d', $date);
        $offset = $page * $length;
        $res = DB::SELECT("SELECT a.`user_id`, a.`from_user_id`,a.`room_wealth_value`, a.`change_timestamp` as change_time,  a.`change_timestamp` as change_timestamp FROM zb_{$this->streamTable} a JOIN (SELECT `stream_id` FROM zb_{$this->streamTable} WHERE `room_id`=? AND DATE(`change_time`)=? LIMIT {$offset},{$length}) b ON a.stream_id=b.stream_id",[$room_id, $date]);
        $res = $this->objToArray($res);
        return $res;
    }

    /**更新当前的魅力值到总魅力值
     * @param $user_id
     */
    public function inc_user_total_score($user_id){
        if(time() >=1606060800 && time()<1607270400){
            $key = $this->redis_charts_user_wealth_day . date('Ymd');
            $today_score = Redis::zscore($key, $user_id) ?? 0;
            $before_score = Redis::zscore($this->redis_finance_user_wealth_before_total, $user_id) ?? 0;
            Redis::zadd($this->redis_finance_user_wealth_total, $today_score+$before_score, $user_id);
        }
    }

    /**获取前20名的总魅力榜单
     * @param $start 开始
     * @param $end 结束
     * @return mixed
     */
    public function get_user_total_score($start,$end){
        return Redis::zrevrange($this->redis_finance_user_wealth_total, $start, $end, 'withscores');
    }

    /**
     * 获取用户昨日/上周/上个月财富值排行榜
     * @param $type 1.天 2.周 -.月 3.总
     * @param $index
     * @param $count
     * @return array
     */
    public function get_before_user_charts($type, $index=0, $count=3){
        $str_month = date("Ym",strtotime("-1 month"));
        $str_day = date("Ymd",strtotime("-1 day"));
        $str_week_start = date("Ymd", strtotime('monday last week'));
        $str_week_end   = date("Ymd", strtotime('monday this week - 1 days'));
        $user_day_key = $this->redis_charts_user_wealth_day . $str_day;
        $user_week_key = $this->redis_charts_user_wealth_week . $str_week_start . $str_week_end;
        $user_month_key = $this->redis_charts_user_wealth_month . $str_month;
        $user_all_key = $this->redis_charts_user_wealth_all;

        $key = $user_day_key;

        if ($type == 1){
            $key = $user_day_key;
        }
        if ($type == 2){
            $key = $user_week_key;
        }
        if ($type == 3){
            $key = $user_month_key;
        }
        return Redis::zrevrange($key, $index, $index+$count-1, 'withscores');
    }

    public function get_before_my_chart($type, $user_id){
        $str_month = date("Ym",strtotime("-1 month"));
        $str_day = date("Ymd",strtotime("-1 day"));
        $str_week_start = date("Ymd", strtotime('monday last week'));
        $str_week_end   = date("Ymd", strtotime('monday this week - 1 days'));
        $user_day_key = $this->redis_charts_user_wealth_day . $str_day;
        $user_week_key = $this->redis_charts_user_wealth_week . $str_week_start . $str_week_end;
        $user_month_key = $this->redis_charts_user_wealth_month . $str_month;

        $key = $user_day_key;

        if ($type == 1){
            $key = $user_day_key;
        }
        if ($type == 2){
            $key = $user_week_key;
        }
        if ($type == 3){
            $key = $user_month_key;
        }

        return Redis::zscore($key,$user_id) ?? 0;
    }

    /**
     * 获取用户昨日/上周/上个月财富值排行榜-最多金
     * @param $type 1.天 2.周 -.月 3.总
     * @param $index
     * @param $count
     * @return array
     */
    public function get_before_user_charts_maximum_gold($type, $index = 0, $count = 3)
    {
        $str_month = date("Ym",strtotime("-1 month"));
        $str_day = date("Ymd",strtotime("-1 day"));
        $str_week_start = date("Ymd", strtotime('monday last week'));
        $str_week_end   = date("Ymd", strtotime('monday this week - 1 days'));
        $user_day_key = $this->redis_charts_user_wealth_day_maximum_gold . $str_day;
        $user_week_key = $this->redis_charts_user_wealth_week_maximum_gold . $str_week_start . $str_week_end;
        $user_month_key = $this->redis_charts_user_wealth_month_maximum_gold . $str_month;
        $key = $user_day_key;
        if ($type == 1){
            $key = $user_day_key;
        }

        if ($type == 2){
            $key = $user_week_key;
        }

        if ($type == 3){
            $key = $user_month_key;
        }

        return Redis::zrevrange($key, $index, $index + $count - 1, 'withscores');
    }

    /**
     * 根据用户id 获取财富值
     * @param $type 1.天 2.周 -.月 3.总
     * @param $user_id
     * @return array
     */
    public function get_my_chart($type, $user_id){
        $str_month = date("Ym");
        $str_day = date("Ymd");
        $first=1;
        $w=date('w',strtotime($str_day));
        $str_week_start=date('Ymd',strtotime("$str_day -".($w ? $w - $first : 6).' days'));
        $str_week_end=date('Ymd',strtotime("$str_week_start +6 days"));
        $user_day_key = $this->redis_charts_user_wealth_day . $str_day;
        $user_week_key = $this->redis_charts_user_wealth_week . $str_week_start . $str_week_end;
        $user_month_key = $this->redis_charts_user_wealth_month . $str_month;

        $key = $user_day_key;

        if ($type == 1){
            $key = $user_day_key;
        }
        if ($type == 2){
            $key = $user_week_key;
        }
        if ($type == 3){
            $key = $user_month_key;
        }

        return Redis::zscore($key,$user_id) ?? 0;
    }

    /**
     * 根据用户id 获取财富值-最多金
     * @param $type 1.天 2.周 -.月 3.总
     * @param $user_id
     * @return array
     */
    public function get_my_chart_maximum_gold($type, $user_id)
    {
        $str_month = date("Ym");
        $str_day = date("Ymd");
        $first=1;
        $w=date('w',strtotime($str_day));
        $str_week_start=date('Ymd',strtotime("$str_day -".($w ? $w - $first : 6).' days'));
        $str_week_end=date('Ymd',strtotime("$str_week_start +6 days"));
        $user_day_key = $this->redis_charts_user_wealth_day_maximum_gold . $str_day;
        $user_week_key = $this->redis_charts_user_wealth_week_maximum_gold . $str_week_start . $str_week_end;
        $user_month_key = $this->redis_charts_user_wealth_month_maximum_gold . $str_month;
        $key = $user_day_key;
        if ($type == 1){
            $key = $user_day_key;
        }
        if ($type == 2){
            $key = $user_week_key;
        }
        if ($type == 3){
            $key = $user_month_key;
        }

        return Redis::zscore($key,$user_id) ?? 0;
    }

    //
    public function getWealthByRoomId ($roomId, $startTime, $endTime) {
        $wealths = DB::table('finance_wealth_stream')
            ->where('room_id', '=', $roomId)
            ->where('change_timestamp', '>=', $startTime)
            ->where('change_timestamp', '<=', $endTime)
            ->select( 'user_id', DB::raw('SUM(wealth_value) as sumValue'))
            ->groupBy('user_id')
            ->get();
        return $wealths;
    }

    // 修改排行缓存
    public function updateMonthCache($strMonth, $wealthValue, $userId) {
        $userMonthKey = $this->redis_charts_user_wealth_month_maximum_gold . $strMonth;
        $userMonthKeyY = $this->redis_charts_user_wealth_month . $strMonth;
        $re = Redis::zincrby($userMonthKey, $wealthValue, $userId);
        if (intval($re) <= 0) {
            Redis::zrem($userMonthKey, $userId);
        }
        $reY = Redis::zincrby($userMonthKeyY, 0-$wealthValue, $userId);
        if (intval($reY) <= 0) {
            Redis::zrem($userMonthKeyY, $userId);
        }
    }

    // 修改排行缓存
    public function updateWeekCache($strWeekStart, $strWeekEnd, $wealthValue, $userId) {
        $userWeekKey = $this->redis_charts_user_wealth_week_maximum_gold . $strWeekStart . $strWeekEnd;
        $userWeekKeyY = $this->redis_charts_user_wealth_week . $strWeekStart . $strWeekEnd;
        $re = Redis::zincrby($userWeekKey, $wealthValue, $userId);
        if (intval($re) <= 0) {
            Redis::zrem($userWeekKey, $userId);
        }
        $reY = Redis::zincrby($userWeekKeyY, 0-$wealthValue, $userId);
        if (intval($reY) <= 0) {
            Redis::zrem($userWeekKeyY, $userId);
        }
    }

    // 修改排行缓存
    public function updateDayCache($strDay, $wealthValue, $userId) {
        $userDayKey = $this->redis_charts_user_wealth_day_maximum_gold . $strDay;
        $userDayKeyY = $this->redis_charts_user_wealth_day . $strDay;
        $re = Redis::zincrby($userDayKey, $wealthValue, $userId);
        if (intval($re) <= 0) {
            Redis::zrem($userDayKey, $userId);
        }
        $reY = Redis::zincrby($userDayKeyY, 0-$wealthValue, $userId);
        if (intval($reY) <= 0) {
            Redis::zrem($userDayKeyY, $userId);
        }
    }

    // 修改排行缓存
    public function updateAllCache($wealthValue, $userId) {
        $userAllKey = $this->redis_charts_user_wealth_all_maximum_gold;
        $userAllKeyY = $this->redis_charts_user_wealth_all;
        Redis::zincrby($userAllKey, $wealthValue, $userId);
        Redis::zincrby($userAllKeyY, 0-$wealthValue, $userId);
    }

    /**
     * 修复最多金富豪月榜缓存
     */
    public function updateWealthMonthChartsCache ($maximumGoldRoomIds, $strMonth, $startTime, $endTime) {
        if (count($maximumGoldRoomIds) > 0) {// 最多金榜单

            $strDay = date("Ymd");
            $first = 1;
            $w = date('w',strtotime($strDay));
            $strWeekStart = date('Ymd',strtotime("$strDay -".($w ? $w - $first : 6).' days'));
            $strWeekEnd = date('Ymd',strtotime("$strWeekStart +6 days"));
            $userWeekKey = $this->redis_charts_user_wealth_week_maximum_gold . $strWeekStart . $strWeekEnd;
            $userMonthKey = $this->redis_charts_user_wealth_month_maximum_gold . $strMonth;
            $userAllKey = $this->redis_charts_user_wealth_all_maximum_gold;


            foreach ($maximumGoldRoomIds as $k => $v) {
                $roomId = (int)$v;
                Log::info('修复最多金富豪月榜缓存:updateWealthMonthChartsCache:房间号:' . $roomId);
                if ($roomId <= 0) {
                    Log::info('修复最多金富豪月榜缓存:updateWealthMonthChartsCache:房间号:' . $roomId . '没有记录');
                    continue;
                }
                $wealthValue = DB::table('finance_wealth_stream')
                    ->where('room_id', '=', $roomId)
                    ->where('change_time', '>=', $startTime)
                    ->where('change_time', '<=', $endTime)
                    ->select('stream_id', 'room_id', 'user_id', 'wealth_value', 'change_time')
                    ->orderBy('stream_id','asc')
                    ->get();
                if (count($wealthValue) <= 0) {
                    Log::info('修复最多金富豪月榜缓存:updateWealthMonthChartsCache:房间号:' . $roomId . '没有流水');
                    continue;
                }

                foreach ($wealthValue as $k=>$v) {
                    Log::info('修复最多金富豪月榜缓存:updateWealthMonthChartsCache:流水ID:' . $v->stream_id);
                    Redis::zincrby($userMonthKey, $v->wealth_value, $v->user_id);
                    Redis::zincrby($userAllKey, $v->wealth_value, $v->user_id);
                    if (strtotime($strWeekStart . '00:00:00') >= strtotime($v->change_time)) {
                        Redis::zincrby($userWeekKey, $v->wealth_value, $v->user_id);
                        $userWeekKeyY = $this->redis_charts_user_wealth_week . $strWeekStart . $strWeekEnd;
                        Redis::zincrby($userWeekKeyY, 0-($v->wealth_value), $v->user_id);
                    }
                    $userMonthKeyY = $this->redis_charts_user_wealth_month . $strMonth;
                    $userAllKeyY = $this->redis_charts_user_wealth_all;
                    Redis::zincrby($userMonthKeyY, 0-($v->wealth_value), $v->user_id);
                    Redis::zincrby($userAllKeyY, 0-($v->wealth_value), $v->user_id);
                }
            }
        }
    }
}
